{% include 'admin/header.html' %}

<script type="text/javascript">
	changeTab('添加管理员');
</script>

<div class="setting-xcontent">
	<div>
		<div class="col-lg-12 col-xs-12">
			<h4><span class="fa fa-hand-o-right"></span> 添加管理员</h4>
		</div>
		<div class="col-lg-6 col-xs-6 col-lg-offset-3 col-xs-offset-3">
			<div class="panel panel-info bd-color-x">
				<div class="panel-heading bg-color-x">
					<span class="">添加管理</span>
				</div>
				<div class="panel-body">
					<form id="add_from" class="form-horizontal" method="post">
						<div class="form-group">
							<label for="user" class="text-left col-lg-3 col-sm-4 control-label">账号</label>
							<div class="col-lg-9 col-sm-8">
								<input id="user" type="text" name="ad_name" class="form-control" placeholder="账号" required>
							</div>
						</div>
                        <div class="form-group">
                            <label for="pass" class="text-left col-lg-3 col-sm-4 control-label">密码</label>
                            <div class="col-sm-8 col-lg-9">
                                <input id="pass" type="password" name="ad_pass" class="form-control" placeholder="密码" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="pass_1" class="text-left col-lg-3 col-sm-4 control-label">确定密码</label>
                            <div class="col-sm-8 col-lg-9">
                                <input id="pass_1" type="password" class="form-control" placeholder="确定密码" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="tel" class="text-left col-lg-3 col-sm-4 control-label">预留电话</label>
                            <div class="col-sm-8 col-lg-9">
                                <input id="tel" type="text" name="ad_tel" class="form-control" maxlength="11" placeholder="电话" required>
                            </div>
                        </div>
						<div class="form-group">
							<label for="t_name" class="text-left text-danger col-lg-3 col-sm-4 control-label">老师称呼</label>
							<div class="col-sm-8 col-lg-9">
								<input id="t_name" type="text" name="teacher_name" class="form-control" placeholder="老师称呼（耿老师）" required>
							</div>
						</div>
						<input type="submit" value="添加" class="btn btn-info btn-group-justified">
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
$('#add_from').submit(function(event) {
	event.preventDefault();
    var data = $('#add_from').serializeArray();

    var p1 = $('#pass').val();
    var p2 = $('#pass_1').val();
    var tel = $('#tel').val();
    if (p1.length < 6) {
        alert("密码不能小于6位");
    } else if (p1 !== p2) {
        alert("两次密码不相同！");
    } else if (!/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/.test(tel)) {
        alert("电话号码格式不正确！");
    } else {
        $.post('/admin/add', data, function(data) {
            if (data.status) {
                alert('SUCCESS: 添加成功！');
                location.href="/admin/list";
            } else {
                alert("ERROR: " + data.msg);
            }
        });
    }
});
</script>
{% include 'admin/footer.html' %}